﻿// =================================================================== 
// Module说明
//====================================================================
// 创建时间：2018-12-17 14:36:02
// 负责人：liucx
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq.Expressions;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using OF.Component.Factory;
using OF.Component.DTO;
using OF.Component.Enum;

namespace OF.Component.BLL
{

    /// <summary>
    ///通知消息 扩展
    /// </summary>
    public partial class MessageOperate
    {
        /// <summary>
    	/// 根据断言条件获取单个通知消息
    	/// </summary>
        public static MessageInfo QuerySingle(Expression<Func<MessageInfo, bool>> predicate)
        {
            return dal.QuerySingle(predicate);
        }
        /// <summary>
    	/// 根据断言条件获获取通知消息列表
    	/// </summary>
        public static IList<MessageInfo> QueryList(Expression<Func<MessageInfo, bool>> predicate)
        {
            return dal.QueryList(predicate);
        }

        public static IList<MessageInfo> SearchList(MessageCondition condition) {
            return dal.SearchList(condition);
        }

        /// <summary>
        /// 分页查询信息
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="regStatus">状态</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageCount">总数</param>
        /// <returns></returns>
        public static DataTable GetMessageTypePage(int userID, int messageType, int pageIndex, int pageSize, out int pageCount)
        {
            return dal.GetMessageTypePage(userID, messageType, pageIndex, pageSize, out pageCount);
        }

        /// <summary>
        /// 设置消息已读
        /// </summary>
        /// <param name="messageID">消息ID</param>
        /// <returns></returns>
        public static int SetMessageRead(long messageID)
        {
            return dal.SetMessageRead(messageID);
        }

        /// <summary>
        /// 获取未读消息并设置未已读
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public static DataTable GetMessagePush(int userID)
        {
            return dal.GetMessagePush(userID);
        }

        /// <summary>
        /// 根据类型分组汇总
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <returns></returns>
        public static DataTable GetMessageTotalType(int userID)
        {
            return dal.GetMessageTotalType(userID);
        }

        /// <summary>
        /// 查询未读消息汇总
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <returns></returns>
        public static int GetMessageTotal(int userID)
        {
            return dal.GetMessageTotal(userID);
        }

        /// <summary>
        /// 发送所有用户消息
        /// </summary>
        /// <param name="msgId"></param>
        /// <returns></returns>
        public static bool SendAllUserMessage(long msgId)
        {
            return dal.SendAllUserMessage(msgId);
        }
        

        /// <summary>
        /// 发送单个用户消息
        /// </summary>
        /// <returns></returns>
        public static bool SendMessageByUser(long userId, MessageTypeEnum msgType, MessageSourceEnum msgSource, string msgTitle, string msgBody, string msgDesc)
        {
            MessageInfo obj = new MessageInfo
            {
                MessageType = (int)msgType,
                CreatedDate = DateTime.Now,
                MessageTitle = msgTitle,
                MessageSource = (int)msgSource,
                OperationID = "0",
                SendDate = DateTime.Now,
                MessageBody = msgBody,
                MessageDesc = msgDesc,
                IsSend = 1
            };
            long msgId = MessageOperate.Insert(obj);
            MessagePoolInfo msgPoolObj = new MessagePoolInfo
            {
                IsActive = 1,//有效状态
                ErrorMessage = "",
                IsRead = 1,
                MessageID = msgId,
                MessageStatus = 1,
                MessageType = (int)msgType,
                SendDate = DateTime.Now,
                UserID = userId
            };
            return MessagePoolOperate.Insert(msgPoolObj) > 0;
        }

        /// <summary>
        /// 获取未读消息
        /// </summary>
        /// <returns></returns>
        public static DataTable GetAllMessagePush()
        {
            return dal.GetAllMessagePush();
        }
    }
}